﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SARUserControls.ChangJingCanshu.DialogFrames;

namespace SARUserControls
{
    /// <summary>
    /// SARDialog.xaml 的交互逻辑
    /// </summary>
    public partial class SARDialog : Window
    {
        public SARDialog()
        {
            this.InitializeComponent();
            // 在此点之下插入创建对象所需的代码。
        }

        private DialogPageBase page;

        public SARDialog(DialogPageBase page)
        {
            this.InitializeComponent();
            // 在此点之下插入创建对象所需的代码。
            this.childFrame.Content = page;
            this.txtTitle.Text = page.getTitle();
            this.page = page;
        }

        private void gridTitle_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        public event OKClickHandler OKClick;
        public event CancelClickHandler CancelClick;

        private void btnOk_SARPreClick(object sender, MouseButtonEventArgs e)
        {
            if (OKClick != null)
            {
                IDictionary<string, object> values = (page as DialogPageBase).getValues();
                if (values != null)
                {
                    OKClick.Invoke(values);
                }
            }
            this.Close();
        }

        private void btnCancel_SARNextClick(object sender, MouseButtonEventArgs e)
        {
            if (CancelClick != null)
            {
                CancelClick.Invoke();
            }
            this.Close();
        }

        private void closeMouseCapture_MouseEnter(object sender, MouseEventArgs e)
        {
            this.closeMouseCapture.Opacity = 1;
        }

        private void closeMouseCapture_MouseLeave(object sender, MouseEventArgs e)
        {
            this.closeMouseCapture.Opacity = 0;
        }

        private void closeMouseCapture_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (CancelClick != null)
            {
                CancelClick.Invoke();
            }
            this.Close();
        }
    }

    public delegate void OKClickHandler(IDictionary<string, object> values);
    public delegate void CancelClickHandler();

}